package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmSensitiveService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult<List<WmChannel>> findAll(){
        return wmChannelService.findAll();
    }

    @PostMapping("/list")
    public ResponseResult<List<WmChannel>> list(@Valid @RequestBody ChannelDto channelDto){
        return wmChannelService.myList(channelDto);
    }

    @GetMapping("del/{id}")
    public ResponseResult<String> del(@PathVariable("id") Integer id){
        return wmChannelService.del(id);
    }

    @PostMapping("/save")
    public ResponseResult<String> save(@RequestBody WmChannel channel){
        return wmChannelService.mySave(channel);
    }

    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody WmChannel channel){
        return wmChannelService.myUpdate(channel);
    }
}
